package com.example.cqcet_demo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;

import com.example.cqcet_demo.R;

public class SplashActivity extends AppCompatActivity {

    private Handler handler = new Handler();
    private boolean flag = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        handler.postDelayed(new Thread() {
            @Override
            public void run() {
                startMainActivity();
                super.run();
            }
        }, 2000);

    }

    private void startMainActivity() {
        if(!flag) {
            Intent intent = new Intent(this, LoginActivity.class);
            startActivity(intent);
            flag = true;
            finish();
        }
    }


    @Override
    protected void onDestroy() {
        handler.removeCallbacksAndMessages(null);
        super.onDestroy();
    }
}
